package br.com.fiap.cincoMob.TrabalhoFinal;

import java.math.BigDecimal;

public class MathUtils {
	
	public static Double CalculationDouble(Double number1, Double number2, String operator){
		Double resultCalculation = 0.0;
		switch (operator) {
		case "+":
			resultCalculation = number1 + number2; 
			break;
		case "-":
			resultCalculation = number1 - number2;
			break;
		case "*":
			resultCalculation = number1 * number2;
			break;
		case "/":
			resultCalculation = number1 / number2;
			break;
		default:
			break;
		}
		
		return resultCalculation;
	}

	public static Double CalculationDouble(Double number1, Double number2, String operator, int decimalSize){
		return truncateNumber(CalculationDouble(number1, number2, operator), decimalSize);
	}	
	
	public static Double truncateNumber(Double number, int decimalSize){
		BigDecimal numberformat = new BigDecimal(number);
		number = numberformat.setScale(decimalSize , BigDecimal.ROUND_HALF_UP).doubleValue();
		return number;
	}
}
